Skip to content

api: add ordered header mutations to ClientTrafficPolicy header filter - #9555

Open
wbpcode wants to merge 2 commits into
envoyproxy:mainfrom
wbpcode:header-mutation-api
Open

api: add ordered header mutations to ClientTrafficPolicy header filter#9555
wbpcode wants to merge 2 commits into
envoyproxy:mainfrom
wbpcode:header-mutation-api

Conversation

@wbpcode

@wbpcode wbpcode commented Jul 22, 2026

Copy link
Copy Markdown
Member

What this PR does / why we need it:

It's usual requirement to control the order of the header mutations. Like we may want to remove some existing headers and then add new one and so on.

And sometimes the users may also want to keep an empty header value if the substitution formatter failed to get the target value.

All these features are supported by the Envoy data plane. This PR add a new fields to the HTTPHeaderFilter to make the users could configure a list of mutations. And the mutations will be applied in definite order.

Which issue(s) this PR fixes:

Fixes #


PR Checklist

  • Authorship & ownership: Coding agents / AI assistants are welcome, but I have reviewed every change, understand how and why it works, can explain and maintain it, and take full responsibility for this PR. I have not submitted generated output I do not understand.
  • DCO: All commits are signed off (git commit -s). See DCO: Sign your work.
  • API agreed first: If this PR contains API changes (changes under /api), the API was discussed and agreed before the implementation. The API change can be in a separate PR, or in the same PR, but the API must be agreed before implementation. N/A if this PR does not contain API changes.
  • Required checks pass: make generate gen-check, make lint, and the unit-test/coverage build pass. (Flaky e2e failures are not considered breakages, but gen-check, lint, and coverage MUST pass.)
  • Tests added/updated: New/changed code is covered by appropriate tests. N/A if this PR does not contain code changes.
  • Docs: User-facing changes update the docs, either in this PR or a follow-up PR. N/A if this PR does not contain user-facing changes.
  • Release notes: For any non-trivial change, added a release-note fragment under release-notes/current/<section>/<pr-number>-<slug>.md (see release-notes/current/README.md for sections and naming). N/A if this PR does not contain non-trivial changes.
  • Generated files committed: Ran make gen-check and committed the result if API/helm charts/modules changed.
  • Scope & compatibility: The PR is reasonably scoped (no unrelated changes) and preserves backward compatibility, or any breaking change is called out above and documented in release-notes/current/breaking_changes/.
  • Codex review: Requested a Codex review and addressed all of its comments.
  • Copilot review: Requested a Copilot review and addressed all of its comments.

@wbpcode
wbpcode requested a review from a team as a code owner July 22, 2026 10:44
@netlify

netlify Bot commented Jul 22, 2026

Copy link
Copy Markdown

Deploy Preview for cerulean-figolla-1f9435 ready!

Name Link
🔨 Latest commit ac5dc32
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/6a60aa8cf3f6800008b9ecf7
😎 Deploy Preview https://deploy-preview-9555--cerulean-figolla-1f9435.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2cd26c73bd

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +1065 to +1067
// +optional
// +kubebuilder:validation:MaxItems=64
Mutations []HTTPHeaderMutation `json:"mutations,omitempty"`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Wire mutations into ClientTrafficPolicy translation

When a ClientTrafficPolicy uses earlyRequestHeaders or lateResponseHeaders with only the new mutations field, the CRD accepts it (and the added CEL test treats it as valid), but the controller still calls translateHeaderModifier, which only reads Add, Set, AddIfAbsent, Remove, and RemoveOnMatch and then reports did not provide valid configuration when those legacy slices are empty (internal/gatewayapi/clienttrafficpolicy.go:1339-1512). In that scenario the newly documented ordered operations never reach the IR/xDS and the policy is rejected or has no header effect, so this API needs corresponding translation/status/testdata support before it is exposed.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for API only discussion.

Comment on lines +1055 to +1067
// Mutations is an ordered list of header operations that are applied in
// exactly the order specified. Use this field when the sequence of
// operations matters, for example setting a header and then appending to
// it, or removing a header and then re-adding it.
//
// Mutations are always applied FIRST, in list order. The Set, Add,
// AddIfAbsent, Remove and RemoveOnMatch fields below are then applied after
// the mutations, preserving their existing ordering (Add, then Set, then
// AddIfAbsent, then Remove, then RemoveOnMatch).
//
// +optional
// +kubebuilder:validation:MaxItems=64
Mutations []HTTPHeaderMutation `json:"mutations,omitempty"`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add a release-note fragment for the new API

This commit exposes a new user-facing ClientTrafficPolicy header-mutation API and updates the generated docs/CRDs, but it does not add any release-notes/current/new_features/... fragment. The repository's release-note workflow expects notable new capabilities and existing API changes to be documented there (release-notes/current/README.md:8-25), so this feature can otherwise ship without appearing in the next release notes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is API only for discussion.

Signed-off-by: wbpcode <wbphub@gmail.com>
@wbpcode
wbpcode force-pushed the header-mutation-api branch from 03e2abf to ac5dc32 Compare July 22, 2026 11:33
// Mutations is an ordered list of header operations that are applied in
// exactly the order specified. Use this field when the sequence of
// operations matters, for example setting a header and then appending to
// it, or removing a header and then re-adding it.

@zhaohuabing zhaohuabing Jul 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this up. Before we settle the shape, the two examples seem not justify the API.

Both examples are already covered by the existing API:

  • "set then append" → the result is just a final value: set: {value: "a,b"} does it in one op.
  • "remove then re-add" → net effect is "header ends up with exactly my value" — that's the definition of set (OVERWRITE_IF_EXISTS_OR_ADD).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, @zhaohuabing . Good point. But note, although we may coalesce multiple values with , (only for inline headers). It's not means they have completely same semantics to for x: a,b and x: a x: b. Esp after we enabled the envoy.reloadable_features.match_headers_individually.

"remove then re-add" → net effect is "header ends up with exactly my value" — that's the definition of set (OVERWRITE_IF_EXISTS_OR_ADD).

When I see remove there, I mean to use remove or remove_on_match. It's very possible for a users to remove a list of headers (like all headers with x-custom- prefix) with remove_on_match and then add a specific one x-custom-specific.

@arkodg arkodg added this to the Backlog milestone Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants